﻿<template>
  <baseConfigUI :config.sync="config" :events.sync="events">
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="数据来源" name="dataSource" v-if="config.other.dataSource">
        <el-card class="box-card">
          <!-- <div slot="header" class="clearfix">
            <span>数据来源</span>
          </div> -->
          <div>
            <el-radio-group v-model="config.other.dataSource.category">
              <el-radio-button label="Meta">元数据表</el-radio-button>
              <el-radio-button label="MetaRef">元数据表关联栏位</el-radio-button>
            </el-radio-group>
            <el-form-item label="数据源">
              <el-select v-model="config.other.dataSource.metaUid" filterable  placeholder="请选择" @change="changMeta">
                <el-option
                  v-for="(item,index) in alltables"
                  :key="index"
                  :label="item.desc"
                  :value="item.uid">
                  <span style="float: left">{{ item.desc }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <template v-if="config.other.dataSource.category==='Meta'">
              <el-form-item label="labelKey">
                <el-select v-model="config.other.dataSource.labelKey" filterable  placeholder="请选择">
                  <el-option
                    v-for="(item,index) in metaColumns"
                    :key="index"
                    :label="item.column_desc"
                    :value="item.column_name">
                    <span style="float: left">{{ item.column_desc }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.column_name }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </template>
          </div>
        </el-card>
      </el-tab-pane>
    </el-tabs>
  </baseConfigUI>
</template>
<script>
import baseConfigUI from '../baseConfigUI.vue'
export default {
  components: {baseConfigUI},
  props: ['config', 'events'],
  data () {
    return {
      activeName: 'dataSource',
      inc_fc: false,
      metaList: [],
      alltables: [],
      metaColumns: [],
      labelKey: ''
    }
  },
  mounted () {
    let self = this
    if (!this.config.other.dataSource) {
      this.$set(this.config.other, 'dataSource', {
        category: 'Meta',
        metaUid: '',
        refColumn: '',
        isDic: false,
        conditions: [],
        fixed_filter: [],
        fixed_orderby: []
      })
    }
    this.$nextTick(() => {
      if (!this.metaList || this.metaList.length <= 0) {
        if (this.inc_fc) {
          self.metaList = window.dformCommon.metaList_inc_fc
        } else {
          self.metaList = window.dformCommon.metaList
        }
      }
      if (!this.alltables || this.alltables.length <= 0) {
        self.alltables = window.dformCommon.alltables
      }
      this.changMeta()
    })
  },
  methods: {
    changMeta () {
      this.metaColumns = []
      let self = this
      var item = this.alltables.find(v => {
        return v.uid === self.config.other.dataSource.metaUid
      })
      if (item) {
        this.config.other.dataSource.isDic = item.category_no === 'DIC'
        this.metaColumns = item.columns
      }
    }
  }
}
</script>

<style lang='scss'>

</style>
